package com.srit.recipes.controller;

import com.srit.recipes.common.response.JpaPage;
import com.srit.recipes.common.response.Response;
import com.srit.recipes.entity.UserInfo;
import com.srit.recipes.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "系统管理")
public class UserController {

    @Autowired
    private UserService userService;


    @GetMapping("/user/login")
    @ApiOperation("1 登录并返回一个token")
    public Response login(String phone, String password) {
        return Response.success(userService.login(phone, password));
    }


    @GetMapping("/user/list")
    @ApiOperation("2 查询当前用户列表")
    public Response userList(JpaPage jpaPage) {
        return Response.success(userService.userList(jpaPage));
    }


    @PostMapping("/user/update")
    @ApiOperation("3 添加或修改一个用户")
    public Response userUpdate(UserInfo userInfo) {
        return Response.success(userService.userUpdate(userInfo));
    }


    @DeleteMapping("/user/delete/{id}")
    @ApiOperation("4 删除用户")
    public Response deleteUser(@PathVariable long id) {
        return Response.success(userService.deleteUser(id));
    }











}
